<template>
  <div class="special-offers">
    <div class="banner">
      <h1>限时特惠</h1>
      <p class="slogan">全场商品低至 <span class="lowest-price">¥{{ lowestPrice.toFixed(2) }}</span>!</p>
    </div>
    <div class="offer-list">
      <div v-for="product in specialOffers" :key="product.id" class="offer-item">
        <router-link :to="{ name: 'ProductDetail', params: { id: product.id } }">
          <div class="offer-image">
            <img :src="product.image" :alt="product.name" />
            <div class="offer-overlay">
              <span class="offer-discount">低至 ¥{{ product.price.toFixed(2) }}</span>
            </div>
          </div>
        </router-link>
        <h3>{{ product.name }}</h3>
        <p class="price">¥{{ product.price.toFixed(2) }}</p>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted, computed } from 'vue';
import { useProductStore } from '../stores/productStore';
const productStore = useProductStore();
const specialOffers = ref([]);
onMounted(() => {
  specialOffers.value = productStore.specialOfferProducts.filter(product => product.specialOffer);
});
const lowestPrice = computed(() => {
  return Math.min(...specialOffers.value.map(product => product.price));
});
</script>
<style scoped>
.special-offers {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}
.banner {
  background: linear-gradient(135deg, #ff4e50, #f9d423);
  color: white;
  padding: 2rem;
  text-align: center;
  border-radius: 8px;
  margin-bottom: 2rem;
}
h1 {
  font-size: 3rem;
  margin-bottom: 1rem;
}
.slogan {
  font-size: 2rem;
  font-weight: bold;
  margin-top: 1rem;
}
.lowest-price {
  font-size: 3rem;
  color: #ff4e50;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.offer-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 2rem;
  justify-items: center;
}
.offer-item {
  border-radius: 8px;
  padding: 1.5rem;
  text-align: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.offer-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.offer-image {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.offer-image img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  transition: transform 0.3s ease;
}
.offer-item:hover .offer-image img {
  transform: scale(1.1);
}
.offer-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.5rem;
  font-size: 1.2rem;
  font-weight: bold;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}
.offer-item:hover .offer-overlay {
  transform: translateY(0);
}
h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  color: #333;
}
.price {
  font-size: 1.5rem;
  font-weight: bold;
  color: #e44d26;
}
</style>
